﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 文明台账数据类
    /// </summary>
    public  class AccManagerDoc
    {
        public AccManagerDoc()
        {
        }
        /// <summary>
        /// 获取首页文明台账（分局传真）列表显示
        /// <creator>wangl</creator>
        /// <date>2014-06-19</date> 
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataTable GetFontList(string entityNo,int top)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT top "+top+" FDocId, ('['+(SELECT FDeptName FROM t_HRDept WHERE");
            strSql.Append(" t_HRDept.FDeptNo=t_accManagerDoc.FDeptNo)+']'+SubString(FFileName,0,1+(Len(FFileName)-CharIndex('.',Reverse(FFileName),0)))) AS title,");
            strSql.Append(" CONVERT(varchar(100), FUpdateTime, 23) AS PubDate FROM t_accManagerDoc ,t_accManagerDir where t_accManagerDoc.FDirId=t_accManagerDir.FDirId");
            strSql.Append(" and t_accManagerDir.FIsBase=1 AND t_accManagerDir.FEntityNo=@FEntityNo ORDER BY FDocId DESC");
         
            SqlParameter[] parameters = {
                   new SqlParameter("@FEntityNo",SqlDbType.VarChar,50)};
            parameters[0].Value = entityNo;
            DataSet ds= DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0];
        }




        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_DSJCJ.Model.AccManagerDoc GetModel(int FDocId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FDocId,FDirId,FEmplNo,FFileName,FFileType,FFileUrl,FFilePath,FUpdateTime,FDispSeq,FEntityNo,FDeptNo,FSize,FIsDelete,FContentTxt,FContentBin,FBGMusicPath,FResponsible,FIsDeptControl,FPlayInterval,FCreateDate,FShowDate,FFileNo,FFileNoDate,FIsSecret from t_accManagerDoc ");
            strSql.Append(" where FDocId=@FDocId");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocId", SqlDbType.Int,4)
			};
            parameters[0].Value = FDocId;

            ElingOA6_DSJCJ.Model.AccManagerDoc model = new ElingOA6_DSJCJ.Model.AccManagerDoc();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_DSJCJ.Model.AccManagerDoc DataRowToModel(DataRow row)
        {
            ElingOA6_DSJCJ.Model.AccManagerDoc model = new ElingOA6_DSJCJ.Model.AccManagerDoc();
            if (row != null)
            {
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = int.Parse(row["FDocId"].ToString());
                }
                if (row["FDirId"] != null && row["FDirId"].ToString() != "")
                {
                    model.FDirId = int.Parse(row["FDirId"].ToString());
                }
                if (row["FEmplNo"] != null)
                {
                    model.FEmplNo = row["FEmplNo"].ToString();
                }
                if (row["FFileName"] != null)
                {
                    model.FFileName = row["FFileName"].ToString();
                }
                if (row["FFileType"] != null)
                {
                    model.FFileType = row["FFileType"].ToString();
                }
                if (row["FFileUrl"] != null)
                {
                    model.FFileUrl = row["FFileUrl"].ToString();
                }
                if (row["FFilePath"] != null)
                {
                    model.FFilePath = row["FFilePath"].ToString();
                }
                if (row["FUpdateTime"] != null && row["FUpdateTime"].ToString() != "")
                {
                    model.FUpdateTime = DateTime.Parse(row["FUpdateTime"].ToString());
                }
                if (row["FDispSeq"] != null && row["FDispSeq"].ToString() != "")
                {
                    model.FDispSeq = int.Parse(row["FDispSeq"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FSize"] != null && row["FSize"].ToString() != "")
                {
                    model.FSize = long.Parse(row["FSize"].ToString());
                }
                if (row["FIsDelete"] != null && row["FIsDelete"].ToString() != "")
                {
                    model.FIsDelete = decimal.Parse(row["FIsDelete"].ToString());
                }
                if (row["FContentTxt"] != null)
                {
                    model.FContentTxt = row["FContentTxt"].ToString();
                }
                if (row["FContentBin"] != null && row["FContentBin"].ToString() != "")
                {
                    model.FContentBin = (byte[])row["FContentBin"];
                }
                if (row["FBGMusicPath"] != null)
                {
                    model.FBGMusicPath = row["FBGMusicPath"].ToString();
                }
                if (row["FResponsible"] != null)
                {
                    model.FResponsible = row["FResponsible"].ToString();
                }
                if (row["FIsDeptControl"] != null && row["FIsDeptControl"].ToString() != "")
                {
                    model.FIsDeptControl = int.Parse(row["FIsDeptControl"].ToString());
                }
                if (row["FPlayInterval"] != null && row["FPlayInterval"].ToString() != "")
                {
                    model.FPlayInterval = int.Parse(row["FPlayInterval"].ToString());
                }
                if (row["FCreateDate"] != null && row["FCreateDate"].ToString() != "")
                {
                    model.FCreateDate = DateTime.Parse(row["FCreateDate"].ToString());
                }
                if (row["FShowDate"] != null && row["FShowDate"].ToString() != "")
                {
                    model.FShowDate = DateTime.Parse(row["FShowDate"].ToString());
                }
                if (row["FFileNo"] != null)
                {
                    model.FFileNo = row["FFileNo"].ToString();
                }
                if (row["FFileNoDate"] != null && row["FFileNoDate"].ToString() != "")
                {
                    model.FFileNoDate = DateTime.Parse(row["FFileNoDate"].ToString());
                }
                if (row["FIsSecret"] != null)
                {
                    model.FIsSecret = row["FIsSecret"].ToString();
                }
            }
            return model;
        }



    }
    
}
